<?php

/*

	WebPhrame - A rudimentary PHP web site framework
	Copyright (c) 2008 Joshua Bodine

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this program.  If not, see
	<http://www.gnu.org/licenses/>.

*/

// Require database interface files for the different types
require_once("webphrame/db_mysql.php");

class DB {
	private $child;
	public $status;

	function __construct($config) {
		// Switch initialization type based on database type
		switch($config['db_type']) {
			case "MySQL":
				// Initialize with MySQL database type
				$this->child = new DBMySQL($config['db_mysql_host'],
						$config['db_mysql_db'],
						$config['db_mysql_user'],
						$config['db_mysql_pass'],
						$config['db_mysql_prf']);

				if($this->child->status)
					// Ugly hack since PHP5 doesn't let us
					// abort in constructors
					$this->status = TRUE;

				break;
			default:
				break;
		}
	}

	public function __call($method, $args) {
		// Call the function
		if(method_exists($this, $method))
			return call_user_func(array($this, $method), $args);
		else if(method_exists($this->child, $method))
			return call_user_func(array($this->child, $method), $args);
		else
			return null;
	}

	public function __get($var) {
		// If it one of ours, return it. Otherwise, pass it on to child
		if(isset($this->{$var}))
			return $this->{$var};
		if(isset($this->child->{$var}))
			return $this->child->{$var};

		return null;
	}
}

?>
